package com.ctsi.hangye.service;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.hangye.domain.Gzhy;
import com.ctsi.hangye.dto.GzhyDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GzhyService {

    @Autowired
    private MybatisGenericDao dao;

    /**
     * 查询我的关注列表
     */
    public List<GzhyDTO> findGzhyDTOList(String userId){
        if (UtilValidate.isEmpty(userId)) {
            return Collections.emptyList();
        }
        Map<String,Object> params = new HashMap<>();
        params.put("userId",userId);
        return (List<GzhyDTO>) this.dao.queryForList(Gzhy.class.getName()+".findGzhyDTOList",params);
    }

    /**
     * 添加关注
     */
    public void addGz(String userId,String hyId){
        if (UtilValidate.isNotEmpty(userId) && UtilValidate.isNotEmpty(hyId)) {
            Gzhy gzhy = new Gzhy();
            gzhy.setId(UUIDGenerator.getId());
            gzhy.setHyId(hyId);
            gzhy.setUserId(userId);
            this.dao.insert(Gzhy.class.getName()+".addGz",gzhy);
        }
    }

    /**
     * 删除我的关注
     */
    public void delGZ(String gzId){
        if (UtilValidate.isNotEmpty(gzId)) {
            Map<String,Object> params = new HashMap<>();
            params.put("gzId",gzId);
            this.dao.remove(Gzhy.class.getName()+".delGz",params);
        }
    }

    /**
     * 获取关注人员的手机号
     */
    public List<String> findPhones(String hyId){
        if (UtilValidate.isNotEmpty(hyId)) {
            Map<String,Object> params = new HashMap<>();
            params.put("hyId",hyId);
            return (List<String>) this.dao.queryForList(Gzhy.class.getName()+".findPhones",params);
        }
        return Collections.emptyList();
    }
}
